<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>5.7 斐波那契</title>
</head>

<body>
    <script>
        // 递归
        function fab1(n) {
            if (n <= 2) {
                return 1
            } else {
                return fab1(n - 1) + fab1(n - 2);
            }
        }
        document.write(fab1(14));
        document.write('<br>');


        // 非递归
        function fab2(n) {
            if (n <= 2) {
                return 1
            }
            var f1 = 1;
            var f2 = 1;
            var temp = 0
            for (var i = 3; i <= n; i++) {
                temp = f1 + f2;
                f1 = f2;
                f2 = temp;
            }
            return temp;
        }
        document.write(fab1(14));
    </script>
</body>

</html>